(function (vc, vm) {

    vc.extends({
        data: {
            editAffiliateCommissionInfo: {
                acId: '',
                commissionRate: '',
                commissionAmount: '',

            }
        },
        _initMethod: function () {

        },
        _initEvent: function () {
            vc.on('editAffiliateCommission', 'openEditAffiliateCommissionModal', function (_params) {
                vc.component.refreshEditAffiliateCommissionInfo();
                $('#editAffiliateCommissionModel').modal('show');
                vc.copyObject(_params, vc.component.editAffiliateCommissionInfo);
                vc.component.editAffiliateCommissionInfo.communityId = vc.getCurrentCommunity().communityId;
            });
        },
        methods: {
            editAffiliateCommissionValidate: function () {
                return vc.validate.validate({
                    editAffiliateCommissionInfo: vc.component.editAffiliateCommissionInfo
                }, {
                    'editAffiliateCommissionInfo.commissionRate': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "佣金比例不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "30",
                            errInfo: "佣金比例不能超过30"
                        },
                    ],
                    'editAffiliateCommissionInfo.commissionAmount': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "佣金金额不能为空"
                        },
                        {
                            limit: "maxLength",
                            param: "200",
                            errInfo: "佣金金额不能为空"
                        },
                    ],
                    'editAffiliateCommissionInfo.acId': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "佣金ID不能为空"
                        }]

                });
            },
            editAffiliateCommission: function () {
                if (!vc.component.editAffiliateCommissionValidate()) {
                    vc.toast(vc.validate.errInfo);
                    return;
                }

                vc.http.apiPost(
                    'affiliateCommission.updateAffiliateCommission',
                    JSON.stringify(vc.component.editAffiliateCommissionInfo),
                    {
                        emulateJSON: true
                    },
                    function (json, res) {
                        //vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
                        let _json = JSON.parse(json);
                        if (_json.code == 0) {
                            //关闭model
                            $('#editAffiliateCommissionModel').modal('hide');
                            vc.emit('affiliateCommissionManage', 'listAffiliateCommission', {});
                            return;
                        }
                        vc.message(_json.msg);
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');

                        vc.message(errInfo);
                    });
            },
            refreshEditAffiliateCommissionInfo: function () {
                vc.component.editAffiliateCommissionInfo = {
                    acId: '',
                    commissionRate: '',
                    commissionAmount: '',

                }
            }
        }
    });

})(window.vc, window.vc.component);
